package com.zr.datamodel;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="sys_func")
public class FuncDM {

	//功能id
	private int id;
	
	//功能名
	private String name;
	
	//父功能
	private FuncDM parentFunc;
	
	//子功能集合
	private List<FuncDM> childrenFuncs;
	
	//功能对应的请求路径
	private String url;
	
	//功能状态
	private String status;
	
	//功能对应的角色
	private List<RoleDM> roles = new ArrayList<>();

	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name="name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne(cascade=CascadeType.ALL)
	public FuncDM getParentFunc() {
		return parentFunc;
	}

	public void setParentFunc(FuncDM parentFunc) {
		this.parentFunc = parentFunc;
	}

	@OneToMany(targetEntity=FuncDM.class, 
			mappedBy="parentFunc",
			cascade=CascadeType.ALL
			)
	public List<FuncDM> getChildrenFuncs() {
		return childrenFuncs;
	}

	public void setChildrenFuncs(List<FuncDM> childrenFuncs) {
		this.childrenFuncs = childrenFuncs;
	}

	@Column(name="url")
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name="status")
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@ManyToMany
	@JoinTable(name="role_func",
		joinColumns=@JoinColumn(name="func_id"),
		inverseJoinColumns=@JoinColumn(name="role_id")
	)
	public List<RoleDM> getRoles() {
		return roles;
	}

	public void setRoles(List<RoleDM> roles) {
		this.roles = roles;
	}
	
}
